<template>
  <header class="site-header site-header__header-one site-header__header-two">
    <nav class="navbar navbar-expand-lg navbar-light header-navigation stricky" style="display: flex">
      <div class="container clearfix">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="logo-box clearfix">
          <a class="bs-navbar-brand" href="/">
            <img
              src="../../../assets/image/logo1.png"
              class="main-logo"
              width="220"
              alt="Awesome Image"
            />
          </a>
          <button class="menu-toggler" data-target=".main-navigation">
            <span class="fa fa-bars"></span>
          </button>
        </div>
        <!-- /.logo-box -->
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="main-navigation">
          <ul class="one-page-scroll-menu navigation-box">
            <li class="current scrollToLink">
              <a href="/cms/home">首页</a>
              <!-- /.sub-menu -->
            </li>
            <li class="scrollToLink">
              <a href="/cms/guide">指南</a>
            </li>
            <li class="scrollToLink">
              <a href="/cms/material">模板</a>
            </li>
            <li class="scrollToLink">
              <a href="/cms/community">素材</a>
            </li>
            <li class="scrollToLink">
              <a href="/cms/qacenter">论坛</a>
            </li>
            <li class="scrollToLink">
              <a href="#news">关于我们</a>
              <!--
              <ul class="sub-menu">
                <li><a href="/cms/blog">News Page</a></li>
                <li><a href="/cms/blogDetails">News Details</a></li>
              </ul>
              -->
              <!-- /.sub-menu -->
            </li>
          </ul>
        </div>
        <!-- /.navbar-collapse -->

        <!-- /.right-side-box -->
      </div>
      <div class="right-menu">
          <div v-if="name" style="display:flex">
          
            <span class="right-menu-item name-container" >您好： {{ name }} </span>
            <span><i class="el-icon-caret-bottom" style="color:#fff" @mouseenter="openDraw()"/></span>
            <div :class="expandClass()"  @mouseleave="closeDraw()">
              <div class="dropdown-title">
                <i class="el-icon-data-line" style="margin-right:5px"></i>
                <router-link to="/tool/datav/datavIndex">
                  我的大屏
                </router-link>
              </div>
              <div class="dropdown-title" @click="logout()">
                <i class="el-icon-switch-button" style="margin-right:5px"></i>
                
                  <span>退出登录</span>
              </div>
            </div>
           <!-- <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
              <div class="avatar-wrapper">
                <img :src="avatar" class="user-avatar">
                <i class="el-icon-caret-bottom" />
              </div>
              <el-dropdown-menu slot="dropdown" style="top:75px !important;">
                <router-link to="/tool/datav/datavIndex">
                  <el-dropdown-item>我的大屏</el-dropdown-item>
                </router-link>
              
                <el-dropdown-item divided @click.native="logout">
                  <span>退出登录</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown> -->
          </div> 
          <div v-if="!name" class="right-menu-item name-container" style="cursor:pointer">
              <div class="login-title">
                <router-link to="/login">
                  <span>登录 </span>
                </router-link>
              </div>  
             <span> | </span>

             <div class="login-title">
               <router-link to="/register">
                <span>注册 </span>
              </router-link>            
             </div>

          </div>
        </div>
      <!-- /.container -->
    </nav>
  </header>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
    data() {
      return {
        flag: false,
      }
    },
    computed: {
    ...mapGetters([
      'avatar',
      'name'
    ]),
    setting: {
      get() {
        return this.$store.state.settings.showSettings
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'showSettings',
          value: val
        })
      }
    }
  },
    methods: {
      openDraw(){
        this.flag = true;
      },
      closeDraw(){
        this.flag = false;
      },      
      expandClass() {
        if (this.flag) {
          return "common-topbar-dropdown";
        } else {
          return "common-topbar-close";
        } 
      },
      async logout() {
        this.$confirm('确定注销并退出系统吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('LogOut').then(() => {
            location.reload()
          })
        })
      }
    },
};
</script>
<style lang="scss" scoped>
/deep/ .navbar>.container, .navbar>.container-fluid {
    display: -ms-flexbox;
    display: block;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -ms-flex-align: center;
    align-items: center;
    -ms-flex-pack: justify;
    justify-content: space-between;
}

.navbar-light .bs-navbar-brand {
    color: rgba(0,0,0,.9);
}
.bs-navbar-brand {
    display: inline-block;
    padding-top: .3125rem;
    padding-bottom: .3125rem;
    margin-right: 1rem;
    font-size: 1.25rem;
    line-height: inherit;
    white-space: nowrap;
}

.container {
    max-width: 1140px;
}

.container {
    margin-top: 10px;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: 60px;
    margin-left: auto;
}
.right-menu {
  width: 130px;
  height: 100%;
  line-height: 50px;
  display: flex;
  float: right;
  margin-top: 32px;
  margin-right: 60px;
  &:focus {
    outline: none;
  }

  .right-menu-item {
    display: flex;
    padding: 0 8px;
    height: 100%;
    font-size: 18px;
    color: #5a5e66;
    vertical-align: text-bottom;

    &.hover-effect {
      cursor: pointer;
      transition: background .3s;

      &:hover {
        background: rgba(0, 0, 0, .025)
      }
    }
  }

  .avatar-container {
    margin-right: 30px;

    .avatar-wrapper {
      margin-top: 5px;
      position: relative;

      .user-avatar {
        cursor: pointer;
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }

      .el-icon-caret-bottom {
        cursor: pointer;
        position: absolute;
        right: -20px;
        top: 25px;
        font-size: 12px;
      }
    }
  }

  .name-container {
    color: #fff;
    font-size: 16px;
  }
}

.common-topbar-dropdown {
  color: #fff;
  background: #fff;
  position: absolute;
  opacity: 1;
  visibility: visible;
  top: 80px;
  right: 40px;
  width: 110px;
  height: 80px;
  z-index: 999;
  box-shadow: 0 12px 10px 0 rgba(0, 0, 0, 0.09);
  transition-property: height;
}
.common-topbar-close{
  color: #fff;
  background: #fff;
  position: absolute;
  top: 80px;
  right: 40px;
  width: 110px;
  opacity: 0;
  height: 0;
  visibility: hidden;
  z-index: 999;
  transition-property: height;
}
.dropdown-title{
  width: 100%;
  height: 50%;
  color: #000;
  font-size: 14px;
  line-height: 36px;
  text-align: center;
  cursor: default;
}
.dropdown-title:hover{
  color: #1890ff;
  background-color: #ecf1f7;
}
.login-title{
  margin: 0 5px;
}
.login-title:hover{
  font-weight: 800;
}
</style>